/*
 * @Author: wwssaabb
 * @Date: 2021-07-27 08:48:37
 * @LastEditTime: 2021-08-13 14:56:26
 * @FilePath: \react-admin-client\src\api\index.js
 */

/* 
  包含应用中所有接口请求函数的模块，返回的是promise对象
*/

import ajax from './ajax'
import axios from 'axios'

const GD_KEY='cee0160bebaf18f246314382d678939a'

//登录请求
export const reqLogin=(username,password,callback)=>ajax('/login',{username,password},'POST',callback)

//获取IP请求（高德）
export const reqGetSite=async ()=>await axios.get('https://restapi.amap.com/v3/ip?key='+GD_KEY)

//获取天气（高德）
export const reqGetWeather=async (city)=>await axios.get('https://restapi.amap.com/v3/weather/weatherInfo?key='+GD_KEY+'&city='+city)

//获取分类信息（暂时用本地爬取的淘宝分类数据）
/* export const reqCategory=async ()=>await new Promise(resolve=>setTimeout(async ()=>{
  resolve(await import('../utils/category.json'))
},1000)) */

//获取分类信息
export const reqCategories=async ()=>ajax('/categories') 

//修改分类名
export const reqCategoryRename=async (params)=>ajax('/rename',params,'POST')

//添加分类
export const reqAddCategory=async (params)=>ajax('/addCategory',params,'POST') 

//添加商品或删除商品
export const reqAddProduct=async (params)=>ajax('/product/addOrDel',params,'POST')

//修改商品
export const reqModifyProduct=async (params)=>ajax('/product/modify',params,'POST')

//获取商品列表
export const reqProductList=async ()=>ajax('/product/list')

//修改商品状态（上架、下架）
export const reqProductUpdateStatus=async (params)=>ajax('/product/updateStatus',params,'POST')

//获取用户列表
export const reqUsers=async ()=>ajax('/users')

//创建用户
export const reqUserCreate=async (params)=>ajax('/user/create',params,'POST')

//删除用户
export const reqUserDelete=async (params)=>ajax('/user/delete',params,'POST')

//修改用户
export const reqUserModify=async (params)=>ajax('/user/modify',params,'POST')

//获取角色列表
export const reqRoles=async ()=>ajax('/roles')

//修改角色权限
export const reqRoleModify=async (params)=>ajax('/role/modify',params,'POST')

//添加角色
export const reqRoleAdd=async (params)=>ajax('/role/add',params,'POST')

//删除图片
export const reqDeleteImg=async (params)=>ajax('/upload/delete',params,'POST')






